package com.leetcode.p0;

import com.bean.ListNode;
import com.utils.DataUtils;

public class Test92 {

    public ListNode reverseBetween(ListNode head, int left, int right) {
        ListNode dummyNode = new ListNode(-1);
        ListNode pre = dummyNode;
        pre.next = head;

        for (int i = 0; i < left - 1; i++) {
            pre = pre.next;
        }

        ListNode cur = pre.next;
        ListNode next = null;

        for (int i = 0; i < right - left; i++) {
            next = cur.next;

            cur.next = next.next;
            next.next=pre.next;
            pre.next=next;
        }
        return dummyNode.next;
    }

    public static void main(String[] args) {
        Test92 test = new Test92();
        ListNode head = DataUtils.getOneToNumberListNode(5);
        DataUtils.printListNode(test.reverseBetween(head, 2, 4));
    }
}
